import request from '@/utils/request'
import { getToken } from '@/utils/storage'

// 轮播图
export function swiper () {
  return request({
    method: 'get',
    url: '/home/swiper'
  })
}

// 租房小组
export function zufang () {
  return request({
    method: 'get',
    url: '/home/groups',
    params: { area: JSON.parse(localStorage.getItem('cityInfo')).value }
  })
}

// 首页资讯
export function news () {
  return request({
    method: 'get',
    url: '/home/news'
  })
}
// 已发布房源列表
export function houseList () {
  return request({
    method: 'get',
    url: '/user/houses'
  })
}

// 房屋详情
export function houseDetail (id) {
  return request({
    method: 'get',
    url: `/houses/${id}`
  })
}
// 收藏
export function collectHouse (id) {
  return request({
    method: 'post',
    url: `/user/favorites/${id}`
  })
}
// 取消收藏
export function xcollect (id) {
  return request({
    method: 'delete',
    url: `/user/favorites/${id}`
  })
}
// 房屋是否收藏
export function xycollect (id) {
  return request({
    method: 'get',
    url: `/user/favorites/${id}`
  })
}

// 小区关键字查询
export function searchArea (name, id) {
  return request({
    method: 'get',
    url: '/area/community',
    params: {
      name,
      id
    }
  })
}

// 发布房源所需条件
export function fabuHouse () {
  return request({
    method: 'get',
    url: '/houses/params'
  })
}

// 发布房源
export function fabuHouseReel (data) {
  return request({
    method: 'post',
    url: '/user/houses',
    data,
    headers: {
      authorization: getToken()
    }
  })
}

// 上传图片
export function fabuImg (data) {
  return request({
    method: 'post',
    url: '/houses/image',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }

  })
}
